package com.velpro.im.controller.base;

import java.util.HashMap;
import java.util.Map;

public class Result extends HashMap<String, Object> {

    public Result() {
        put("code", 0);
    }

    public static Result fail() {
        return error(500, "未知异常，请联系管理员");
    }

    public static Result error(String msg) {
        return error(400, msg);
    }

    public static Result error(int code, String msg) {
        Result r = new Result();
        r.put("code", code);
        r.put("msg", msg);
        return r;
    }

    public static Result ok(Object data) {
        Result r = new Result();
        r.put("data", data);
        return r;
    }

    public static Result ok() {
        return new Result();
    }

    @Override
    public Result put(String key, Object value) {
        super.put(key, value);
        return this;
    }
}
